# Copyright 2024 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

load("@rules_cc//cc:cc_library.bzl", "cc_library")
load(
    "@rules_fuchsia//fuchsia:defs.bzl",
    "fuchsia_cc_test",
    "fuchsia_unittest_package",
)
load("@rules_python//sphinxdocs:sphinx_docs_library.bzl", "sphinx_docs_library")
load("//pw_bluetooth_sapphire/fuchsia:fuchsia_api_level.bzl", "FUCHSIA_API_LEVEL")
load("//pw_build:compatibility.bzl", "incompatible_with_mcu")

package(default_visibility = ["//visibility:public"])

licenses(["notice"])

# Backend for pw_async:task
cc_library(
    name = "task",
    srcs = [
        "task.cc",
    ],
    hdrs = [
        "public/pw_async_fuchsia/task.h",
        "public_overrides/pw_async_backend/task.h",
    ],
    includes = [
        "public",
        "public_overrides",
    ],
    target_compatible_with = ["@platforms//os:fuchsia"],
    deps = [
        ":util",
        "//pw_async:task.facade",
        "@fuchsia_sdk//pkg/async-loop-default",
        "@fuchsia_sdk//pkg/zx",
    ],
)

# Backend for pw_async:fake_dispatcher
cc_library(
    name = "fake_dispatcher",
    testonly = True,
    srcs = [
        "fake_dispatcher.cc",
    ],
    hdrs = [
        "public/pw_async_fuchsia/fake_dispatcher.h",
        "public_overrides/pw_async_backend/fake_dispatcher.h",
    ],
    includes = [
        "public",
        "public_overrides",
    ],
    deps = [
        ":task",
        "//pw_async:fake_dispatcher.facade",
    ],
)

cc_library(
    name = "dispatcher",
    srcs = [
        "dispatcher.cc",
    ],
    hdrs = [
        "public/pw_async_fuchsia/dispatcher.h",
    ],
    includes = [
        "public",
        "public_overrides",
    ],
    deps = [
        ":task",
        "//pw_async:dispatcher",
        "@fuchsia_sdk//pkg/async-cpp",
    ],
)

cc_library(
    name = "util",
    hdrs = [
        "public/pw_async_fuchsia/util.h",
    ],
    includes = [
        "public",
        "public_overrides",
    ],
    tags = ["noclangtidy"],
)

fuchsia_cc_test(
    name = "pw_async_fuchsia_test",
    srcs = [
        "dispatcher_test.cc",
        "fake_dispatcher_fixture_test.cc",
    ],
    deps = [
        ":dispatcher",
        "//pw_async:fake_dispatcher_fixture",
        "//pw_unit_test",
        "//pw_unit_test:printf_main",
        "@fuchsia_sdk//pkg/async-testing",
    ],
)

fuchsia_unittest_package(
    name = "test_pkg",
    package_name = "pw_async_fuchsia_tests",
    fuchsia_api_level = FUCHSIA_API_LEVEL,
    tags = ["manual"],
    unit_tests = [":pw_async_fuchsia_test"],
)

sphinx_docs_library(
    name = "docs",
    srcs = [
        "docs.rst",
    ],
    prefix = "pw_async_fuchsia/",
    target_compatible_with = incompatible_with_mcu(),
)
